package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.view.View;
import android.widget.ImageView;
import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.ItemGuideUserMultiImageBinding;
import com.jwdf.uda.ui.activity.PhotoActivity;
import com.jwdf.uda.ui.activity.UserInfoActivity;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.GuideDetailItem;
import com.jwdf.uda.utils.DateUtils;
import com.jwdf.uda.view.GridImageLayout;
import java.util.ArrayList;
import java.util.List;

/**
 * 类说明：
 */
public class GuideUserMultiImageViewHolder extends AbsViewHolder<GuideDetailItem> {
    private ItemGuideUserMultiImageBinding mItemBinding;
    public GuideUserMultiImageViewHolder(View convertView) {
        super(convertView);
        mItemBinding = DataBindingUtil.bind(convertView);
        mItemBinding.topLayout.tvName.setOnClickListener(this);
        mItemBinding.topLayout.ivHeader.setOnClickListener(this);
    }

    @Override
    protected void onBindView(GuideDetailItem item) {
        PbBean.PbGuideSimple guideInfo = item.guideSimple;
        if(guideInfo == null) return;
        mItemBinding.setIsDesigner(guideInfo.getUserInfo().getIsDesigner());
        mItemBinding.tvTime.setVisibility(View.VISIBLE);
        mItemBinding.tvTime.setText(DateUtils.getFriendlyTime(guideInfo.getTime()));
        GuideUserTxtViewHolder.onBindCommonView(mItemBinding.topLayout, guideInfo);

        final List<PbBean.PbImage> images = guideInfo.getImageListList();
        final ArrayList<String> urls = new ArrayList<String>();
        for (PbBean.PbImage image : images) {
            urls.add(image.getUrl());
        }
        mItemBinding.gridimageLayout.setImage(urls);
        mItemBinding.gridimageLayout.setOnImageItemClickListener(new GridImageLayout.OnImageItemClickListener() {
            @Override
            public void onImageClick(int index, ImageView imageView) {
                PhotoActivity.start(imageView.getContext(), urls, index);
            }
        });
//        if(item.userShow != null && item.userShow.getId() > 0){
//            mItemBinding.gapLayout.setVisibility(View.GONE);
//        }else{
//            mItemBinding.gapLayout.setVisibility(View.VISIBLE);
//        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ivHeader:
            case R.id.tvName:
                if(item.guideSimple != null){
                    UserInfoActivity.start(v.getContext(), item.guideSimple.getUserInfo().getUserId(), item.guideSimple.getUserInfo().getIsDesigner());
                }
                break;
        }
    }
}
